package com.integration.rest.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.json.JSONException;

import com.integration.pojo.TwittMessage;
import com.integration.rest.client.RestClient;



public class Main {

	public static void main(String[] args) throws ParseException {
		//startServer();
		runClient();
	}

	private static void startServer() {
		JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
		bean.setServiceClass(RetrieveService.class);
		bean.setAddress("http://localhost:8089/lp2p");
		bean.setServiceBeanObjects(new RetrieveService());
		bean.create().start();
	}
	
	private static void runClient() {
		RestClient a = new RestClient();
		try {
			List<TwittMessage> listMsgs = a.getListMsgs();
			int i=0;
			for (TwittMessage msg : listMsgs) {
				String text = msg.getText();
				Date data = msg.getCreated_at();
				String name = msg.getUser().getName();
				new SimpleDateFormat("dd/MM/yyyy HH:mm");
				System.out.println(String.format("%2d-%s %s: %s",++i,(new SimpleDateFormat("dd/MM/yyyy HH:mm")).format(data),name,text));
			}
			
			
		} catch (JSONException e) {
			e.printStackTrace();
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
}
	